-- 注意：此库全局通用，和此库相对的是世界管理库，那个只能在世界中使用
-- 此库的所有方法都涉及IO操作，任何时候都不要连续使用！


local file_sys = require "libs/filehandle"
local t_util = require "libs/tableutil"
local data_index = "ShroomCakeSettings.txt"
local MAP_ID_PREFIX,List_ID_PREFIX,Line_ID_PREFIX = file_sys:GetPrefix()

local SM = {}
local data = {}

local function GetSettingData()
    data = file_sys:DataFromJsonLine(data_index)
    return data
end

local function Save()
    file_sys:FuckTableToDataFile(data_index,data)
end

function SM:GetSettingMap(id)
    data = GetSettingData()
    local id = MAP_ID_PREFIX..tostring(id)
    if type(data[id]) ~= "table" then
        data[id] = {}
    end
    return data[id]
end
function SM:GetSettingList(id)
    data = GetSettingData()
    local id = List_ID_PREFIX..tostring(id)
    if type(data[id]) ~= "table" then
        data[id] = {}
    end
    return data[id]
end
function SM:GetSettingLine(id)
    data = GetSettingData()
    local id = Line_ID_PREFIX..tostring(id)
    if type(data[id]) ~= "table" then
        data[id] = {}
    end
    return data[id]
end
function SM:SaveSettingMap(id, map)
    data = GetSettingData()
    data[MAP_ID_PREFIX..tostring(id)] = map
    Save()
end
function SM:SaveSettingList(id, list)
    data = GetSettingData()
    data[List_ID_PREFIX..tostring(id)] = list
    Save()
end
function SM:SaveSettingLine(id, line)
    data = GetSettingData()
    data[Line_ID_PREFIX..tostring(id)] = line
    Save()
end

return SM